package uk.ac.cam.bt288.DesktopApp;

import java.io.File;
import java.io.IOException;

import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

public class QRGenerator {
	public static boolean generate (String s) {
	    // get a byte matrix for the data
	    BitMatrix matrix = null;
	    int h = 400;
	    int w = 400;
	    com.google.zxing.Writer writer = new QRCodeWriter();
	    try {
	        matrix = writer.encode(s, com.google.zxing.BarcodeFormat.QR_CODE, w, h);
	    } catch (com.google.zxing.WriterException e) {
	        System.out.println(e.getMessage());
	    }

	    String filePath = "qr_png.png";
	    File file = new File(filePath);
	    try {
	        MatrixToImageWriter.writeToFile(matrix, "PNG", file);
	        System.out.println("printing to " + file.getAbsolutePath());
	    } catch (IOException e) {
	        System.out.println(e.getMessage());
	    }

		return true;
	}
	
	public static void main (String[] args) {
		QRGenerator.generate("Hello world!");
	}
}
